package com.isoft.course.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.isoft.question.domain.Question;
import com.isoft.question.service.IQuestionService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.isoft.course.domain.MyCourse;
import com.isoft.course.service.IMyCourseService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 我的课程Controller
 * 
 * @author lgm
 * @date 2024-07-20
 */
@RestController
@RequestMapping("/MyCourse/MyCourse")
public class MyCourseController extends BaseController
{
    @Autowired
    private IMyCourseService myCourseService;
    @Autowired
    private IQuestionService questionService;

    /**
     * 查询我的课程列表
     */
    @PreAuthorize("@ss.hasPermi('MyCourse:MyCourse:list')")
    @GetMapping("/list")
    public TableDataInfo list(MyCourse myCourse)
    {
        startPage();
        List<MyCourse> list = myCourseService.selectMyCourseList(myCourse);
        return getDataTable(list);
    }
    /**
     * 查询答题管理列表
     */
//    @PreAuthorize("@ss.hasPermi('question:question:list')")
    @PreAuthorize("@ss.hasPermi('MyCourse:MyCourse:list')")
    @GetMapping("/listQuestion")
    public TableDataInfo list(Question question)
    {
        startPage();
        List<Question> list = questionService.selectQuestionList(question);
        return getDataTable(list);
    }
    /**
     * 查询我的课程列表【管理学生课程表查询】
     */
    @PreAuthorize("@ss.hasPermi('MyCourse:MyCourse:list')")
    @GetMapping("/listStudentCourse")
    public TableDataInfo studentCourseList(MyCourse myCourse)
    {
        startPage();
        List<MyCourse> list = myCourseService.selectStudentCourseList(myCourse);
        return getDataTable(list);
    }

    /**
     * 导出我的课程列表
     */
    @PreAuthorize("@ss.hasPermi('MyCourse:MyCourse:export')")
    @Log(title = "我的课程", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, MyCourse myCourse)
    {
        List<MyCourse> list = myCourseService.selectMyCourseList(myCourse);
        ExcelUtil<MyCourse> util = new ExcelUtil<MyCourse>(MyCourse.class);
        util.exportExcel(response, list, "我的课程数据");
    }

    /**
     * 获取我的课程详细信息
     */
    @PreAuthorize("@ss.hasPermi('MyCourse:MyCourse:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(myCourseService.selectMyCourseById(id));
    }

    /**
     * 新增我的课程
     */
    @PreAuthorize("@ss.hasPermi('MyCourse:MyCourse:add')")
    @Log(title = "我的课程", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody MyCourse myCourse)
    {
        return toAjax(myCourseService.insertMyCourse(myCourse));
    }

    /**
     * 修改我的课程
     */
    @PreAuthorize("@ss.hasPermi('MyCourse:MyCourse:edit')")
    @Log(title = "我的课程", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody MyCourse myCourse)
    {
        return toAjax(myCourseService.updateMyCourse(myCourse));
    }

    /**
     * 修改答题管理
     * @param question
     * @return
     */
    @PreAuthorize("@ss.hasPermi('MyCourse:MyCourse:edit')")
    @Log(title = "答题管理", businessType = BusinessType.UPDATE)
    @PutMapping("/editQuestion")
    public AjaxResult edit(@RequestBody Question question)
    {
        return toAjax(questionService.updateQuestion(question));
    }
    /**
     * 删除我的课程
     */
    @PreAuthorize("@ss.hasPermi('MyCourse:MyCourse:remove')")
    @Log(title = "我的课程", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(myCourseService.deleteMyCourseByIds(ids));
    }
}
